#include <iostream>
#include <vector>
using namespace std;

class TreeArray {
    vector<int> tr;
    int size{0};
public:
    TreeArray(int n) : size{n + 1} {
        tr = vector<int>(size);
    }

    // 添加v到x的位置
    void add(int x, int v) {
        for (int i = x; i < size; i += lowbit(i)) tr[i] += v; 
    };
    // 查找[1, x]的和
    int find(int x) {
        int res = 0;
        for (int i = x; i >= 1; i -= lowbit(i)) res += tr[i];
        return res;
    };

private:
    int lowbit(int x) {
        return x & (-x);
    };
};